<template>
  <div>
    <el-card>
      <!--      -->
      <el-row :gutter="25">
        <!--        添加搜索区-->
        <el-col span="10">
          <el-input placheholder="请输入内容">
            <!--            搜索按钮-->
            <el-button slot="append" icon="el-icon-search">搜索</el-button>
          </el-input>
        </el-col>

        <el-col :span="4">
          <el-button type="primary" @click="addUser">添加用户</el-button>
        </el-col>
        <br>
      </el-row>

      <el-table
        :data="userList"
        border
        stripe
        :row-class-name="tableRowClassName"
      >

        <el-table-column
          prop="id"
          label="ID"
          width="80"
        />

        <el-table-column
          prop="code"
          label="学号"
          width="85"
        />

        <el-table-column
          prop="fullName"
          label="姓名"
          width="85"
        />

        <el-table-column
          prop="address"
          label="地址"
          width="100"
        />

        <el-table-column
          prop="gender"
          label="gender"
          width="85"
        />

        <el-table-column
          prop="grade"
          label="年级"
          width="85"
        />

        <el-table-column
          prop="major"
          label="主修课程"
          width="90"
        />

        <el-table-column
          prop="dateCreated"
          label="创建时间"
          width="100"
        />

        <el-table-column
          prop="dateModified"
          label="修改时间"
          width="100"
        />

        <el-table-column label="操作" width="180px">
          <template>
            <!-- 修改 -->
            <el-button type="primary" icon="el-icon-edit" size="mini" />
            <!-- 删除 -->
            <el-button type="danger" icon="el-icon-delete" size="mini" />
            <!-- 权限 -->
            <el-tooltip effect="dark" content="分配权限" placement="top-start" :enterable="false">
              <el-button type="warning" icon="el-icon-setting" size="mini" />
            </el-tooltip>
          </template>
        </el-table-column>

      </el-table>
      <el-pagination
        :current-page="this.queryInfo.pageNum"
        :page-sizes="[5,10,15]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.totalNumber"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>

    <!--    新建用户对话框-->
    <el-dialog
      title="添加用户"
      :visible.sync="addDialogVisible"
      with="50%"
      @close="addDialogClosed"
    >
      <el-form :model="addForm">
        <el-form-item>
          <el-input v-model="addForm.code" />
        </el-form-item>

        <el-form-item>
          <el-input v-model="addForm.fullName" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="addForm.gender" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="addForm.grade" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="addForm.major" />
        </el-form-item>
      </el-form>

    </el-dialog>

  </div>
</template>

<script>
export default {
  data() {
    return {
      queryInfo: {
        pageNum: 0,
        pageSize: 5
      },
      userList: [],
      totalNumber: 0,
      addForm: {
        code: '',
        fullName: '',
        address: '',
        gender: '',
        grade: '',
        major: ''
      }
    }
  },
  created() {
    this.getStudentList()
  },
  methods: {

    async getStudentList() {
      // eslint-disable-next-line no-unused-vars
      const { data: res } = await this.$http.post('/api/teach/student/findAll/' + this.queryInfo.pageNum + '/' + this.queryInfo.pageSize)
      this.userList = res.userList
      this.totalNumber = res.number
    },

    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize
      this.getStudentList()
    },

    handleCurrentChange(newNum) {
      this.queryInfo.pageNum = newNum
      this.getStudentList()
    },

    // eslint-disable-next-line no-unused-vars
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 0) {
        return 'warn-row'
      } else if (rowIndex % 2 != 0) {
        return 'success-row'
      }
    },
    addUser() {
      this.$prompt('请输入邮箱', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        inputErrorMessage: '邮箱格式不正确'
      }).then(({ value }) => {
        this.$message({
          type: 'success',
          message: '你的邮箱是: ' + value
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    }
    // addDialogVisible(){
    //
    // },
    // addDialogClosed(){
    //
    // },
  }

}
</script>

<style >
.el-table .warning-row {
  background-color: black;
}

.el-table .success-row {
  background-color: #f0f9eb;
}

</style>
